package br.com.escolaespacocrianca.fineec.component;

import java.util.ResourceBundle;

import br.com.caelum.vraptor.Convert;
import br.com.caelum.vraptor.Converter;
import br.com.caelum.vraptor.ioc.ApplicationScoped;

@Convert(Integer.class)
@ApplicationScoped
public class IntegerInterceptor implements Converter<Integer> {

    public Integer convert(String value, Class<? extends Integer> type, ResourceBundle bundle) {
        if (value == null || value.equals("")) {
            return null;
        }
        try {
            return Integer.valueOf(value);
        } catch (NumberFormatException e) {
        	return null;
			//throw new 
			//ConversionError(MessageFormat.format(bundle.getString("is_not_a_valid_integer"), value));
        }
    }

}
